<%--
  User: naim
  Date: Dec 23, 2009
--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="/c.tld" %>
<html>
<head>
    <title>DSE ALERT! :: Refresh</title>
    <link href="<c:url value='/css/common.css'/>" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="/js/jquery-1.3.2.min.js"></script>

</head>
<body>

<div id="page-header">
    Latest Price List
</div>

<table id="latestPriceTable">
</table>

<script type="text/javascript">
    $(document).ready(function () {
        readLatestPrice();
    });

    setInterval(readLatestPrice, 5 * 60 * 1000); //every 5 mins

    function readLatestPrice() {
        $.ajax({
            url: "/ajax/refresh",
            type: "GET",
            dataType: "json",
            success: function(data) {
                var text = drawTableData(data);
                $("#latestPriceTable").html(text);
            }
        });
        window.focus();
    }

    function drawTableData(data) {
        var dt = data["dt"];
        var items = data["items"];
        var text = "";
        var item;
        if (items) {
            window.innerHeight = 100 + (items.length * 20);
            var i;
            for (i = 0; i < items.length; i++) {
                var low = items[i].low;
                var high = items[i].high;

                var className = "data";
                if (low == "true" || high == "true") {
                    className = "data-highlighted";
                }
                text += "<tr>";

                text += "<td class='" + className + "'>" + items[i].name + "</td>";
                text += "<td class='" + className + "'>" + items[i].price;
                if (items[i].myPrice != null) {
                    text += "<sub>(" + items[i].myPrice + ")</sub>";
                }
                text += "</td>";
                text += "<td class='" + className + "'>"
                if (low == "true") {
                    text += "<img src='/images/down.gif' alt='Low!'/>"
                }
                if (high == "true") {
                    text += "<img src='/images/up.gif' alt='High!'/>"
                }
                text += "</td>"
                
                text += "</tr>";
            }
            text += "<tr><td colspan='3' class='info'>" + dt + "</td></tr>";
        }
        return text;
    }
</script>
</body>
</html>